#include <windows.h>
#include <Winbase.h>
#include "CE_SETUP.H"

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
    switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:
		case DLL_THREAD_ATTACH:
		case DLL_THREAD_DETACH:
		case DLL_PROCESS_DETACH:
			break;
    }
    return TRUE;
}

extern "C" codeINSTALL_INIT Install_Init(HWND hwndParent, BOOL fFirstCall, BOOL fPreviouslyInstalled, LPCTSTR pszInstallDir )
{
	return codeINSTALL_INIT_CONTINUE;
}

extern "C" codeINSTALL_EXIT Install_Exit(
    HWND    hwndParent,
    LPCTSTR pszInstallDir,      // final install directory
    WORD    cFailedDirs,
    WORD    cFailedFiles,
    WORD    cFailedRegKeys,
    WORD    cFailedRegVals,
    WORD    cFailedShortcuts
)
{
	PROCESS_INFORMATION pi;
	if ( CreateProcess(
		  _T("\\windows\\cgacutil.exe")
		, _T("/silent /id \\WINDOWS\\Microsoft .NET Compact Framework 1.0.GAC")
		, NULL, 0, false, 0, NULL, NULL, NULL, &pi ) )
	{
		WaitForSingleObject( pi.hProcess, INFINITE );

//		DeleteFile( _T("\\WINDOWS\\Microsoft .NET Compact Framework 1.0.GAC") );
	}

	if (pi.hProcess) CloseHandle( pi.hProcess );
	if (pi.hThread ) CloseHandle( pi.hThread  );

	return codeINSTALL_EXIT_DONE;
}

extern "C" codeUNINSTALL_INIT Uninstall_Init( HWND hwndParent, LPCTSTR pszInstallDir )
{
	DeleteFile( _T("\\WINDOWS\\Microsoft .NET Compact Framework 1.0.GAC") );

	PROCESS_INFORMATION pi;
	if ( CreateProcess(
		  _T("\\windows\\cgacutil.exe")
		, _T("/silent /u Microsoft .NET Compact Framework 1.0.GAC")
		, NULL, 0, false, 0, NULL, NULL, NULL, &pi ) )
	{
		WaitForSingleObject( pi.hProcess, INFINITE );
	}

	if (pi.hProcess) CloseHandle( pi.hProcess );
	if (pi.hThread ) CloseHandle( pi.hThread  );

	return codeUNINSTALL_INIT_CONTINUE;
}

extern "C" codeUNINSTALL_EXIT Uninstall_Exit( HWND hwndParent )
{
	return codeUNINSTALL_EXIT_DONE;
}
